// Copyright 2011 Google Inc.
// Author: moesenle@google.com (Lorenz Moesenlechner)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "ros_check/ros_check.h"

#include <gtest/gtest.h>

TEST(RosCheck, ChecksSucceeding) {
  CHECK(true == true);
  CHECK_EQ(true, true);
  CHECK_NE(true, false);
  CHECK_LE(1, 2);
  CHECK_LE(1, 2);
  CHECK_LT(1, 2);
  CHECK_GE(2, 1);
  CHECK_GE(2, 2);
  CHECK_GT(2, 1);
}

// It seems like ASSERT_DEATH doesn't take the code generated by our
// check macros. We have to put the tests into functions.
static void CheckFail() {
  CHECK(true == false);
}

static void CheckEqFail() {
  CHECK_EQ(true, false);
}

static void CheckNeFail() {
  CHECK_NE(true, true);
}

static void CheckLeFail() {
  CHECK_LE(2, 1);
}

static void CheckLtFail1() {
  CHECK_LT(2, 1);
}

static void CheckLtFail2() {
  CHECK_LT(2, 2);
}

static void CheckGeFail() {
  CHECK_GT(1, 2);
}

static void CheckGtFail1() {
  CHECK_GT(1, 2);
}

static void CheckGtFail2() {
  CHECK_GT(2, 2);
}

TEST(RosCheck, CheckDying) {
  ASSERT_DEATH(CheckFail(), "");
  ASSERT_DEATH(CheckEqFail(), "");
  ASSERT_DEATH(CheckNeFail(), "");
  ASSERT_DEATH(CheckLeFail(), "");
  ASSERT_DEATH(CheckLtFail1(), "");
  ASSERT_DEATH(CheckLtFail2(), "");
  ASSERT_DEATH(CheckGeFail(), "");
  ASSERT_DEATH(CheckGtFail1(), "");
  ASSERT_DEATH(CheckGtFail2(), "");
}

int main(int argc, char *argv[]) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
